﻿using System;
using System.Collections.Generic;
using System.Linq;
using Bintje;

public partial class UI_trail_comments : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillComments();
        }
    }
    public void FillComments()
    {
        if (Request["tid"] != null)
        {
            int tid = 0;
            int.TryParse(Request["tid"], out tid);
            if (tid > 0)
            {
                Bintje.Trail trail = Bintje.Trail.Get(tid);
                if (null != trail && trail.Annotations != null)
                {
                    IList<Annotation> tc = trail.Annotations;
                    rptrTrailComments.DataSource = tc;
                    rptrTrailComments.DataBind();

                    if(tc.Count == 0)
                        lblComments.Text = "no comments available";
                }

                if(null != trail)
                {
                    lblTrailName.Text = trail.Title;
                    WayPoint waypoint = null;
                    try
                    {
                        waypoint = trail.Waypoints[0];
                    }
                    catch (Exception) {}
                    if (null != waypoint)
                    {
                        lblLOcation.Text = waypoint.City;
                        lblCoordinates.Text = waypoint.Latitude + ", " + waypoint.Longitude;
                    }

                    if(null != trail.User)
                        lblUploaded.Text = trail.User.NickName;
                    lblUploaded.NavigateUrl = string.Format("~/UI/userDetail.aspx?uid={0}", trail.Id/*t[0].ID*/);
                    lblStory.Text = trail.Description;

                }
            }
        }
    }
    protected void btnSearchGo_click(object sender, EventArgs e)
    {
        Response.Redirect(string.Format("~/UI/TrailList.aspx?keywords={0}", txtSearchTrail.Text.Replace(" ", "+")));
    }
}
